/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.dspl.validate.violation;

/**
 * Simple renderer for violations that uses the default template.
 * To create your own renderer, it is recommended that you extend this class. That way you will
 * get the default message rendering if new violations are added in future releases.
 *
 * <p>This class uses String.format, therefore it is <strong>not</strong> GWT-compatible.
 *
 * @author maryla@google.com (Maryla Ustarroz Calonge)
 */
public class SimpleViolationRenderer implements ViolationVisitor<String> {

  public String render(Violation violation) {
    return violation.accept(this);
  }

  @Override
  public String visit(InvalidIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(DuplicateIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(InfoNoInfoViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(InfoNoNameViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(InfoNoNameInLanguageViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(DatasetNoIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptNoIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptNoTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptParentConceptNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptConflictingParentTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptInheritanceCycleViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptTopicNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptMappingTableNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptConflictingDefaultValueTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptUnusedViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(DimensionConceptNoDataViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(DimensionConceptProblematicTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptAttributeNoIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptAttributeNoTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptAttributeConflictingParentTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptAttributeConflictingValueConceptTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptAttributeConceptNotFound violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptAttributeValueConceptDoesNotExtendParentConcept violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptPropertyNoIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptPropertyNoTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptPropertyConceptNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptPropertyConflictingConceptTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(TableNoIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(TableNoColumnsViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(TableDefinesMultipleConceptsViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(TableUsedByMultipleSlicesViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(TableDefinesConceptAndUsedInSliceViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ColumnNoIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ColumnNoTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ColumnConflictingConstantValueTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(SliceNoIdViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(SliceDuplicateConceptViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(SliceConceptNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(SliceColumnNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(SliceTableNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(SliceConflictingTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptMappingColumnNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptMappingPropertyColumnNotFoundViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(
      ConceptMappingConflictingColumnTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(ConceptMappingConflictingPropertyColumnTypeViolation violation) {
    return formatMessage(violation);
  }

  @Override
  public String visit(EntityConceptNoNamePropertyMappingViolation violation) {
    return formatMessage(violation);
  }

  private String formatMessage(Violation violation) {
    return String.format(violation.getDefaultTemplate(), violation.getDefaultTemplateParameters());
  }
}
